from src.utils.method import Method
from src.conf.base_conf import BaseConf


class RobotConf(BaseConf):
    """机器人配置文件"""
    def __init__(self, path: str):
        super().__init__(path)

    def _reload_from_dict(self, conf_dict: dict):
        self.on = conf_dict.get("启用机器人", True)
        # 解析域名获取ip地址
        self.__address = conf_dict.get("机器人地址", "127.0.0.1")
        self.host = Method.get_host_by_name(self.__address)
        self.port = conf_dict.get("机器人端口", 3001)
        self.node = conf_dict.get("连接节点", "")
        self.token = conf_dict.get("access-token", "WERTYUIO")
        self.owners = conf_dict.get("管理员QQ号", [2021583736, 1234567890])
        self.allow_group_admin = conf_dict.get("授权群管理员", False)
        self.group = conf_dict.get("管理QQ群号", 531241108)
        self.record_rename = conf_dict.get("自动修改群昵称", "")

    def _check(self):
        pass

    def __str__(self):
        conf_dict = {
            "启用机器人": self.on,
            "机器人地址": self.__address,
            "机器人端口": self.port,
            "连接节点": self.node,
            "access-token": self.token,
            "管理员QQ号": self.owners,
            "授权群管理员": self.allow_group_admin,
            "管理QQ群号": self.group,
            "自动修改群昵称": self.record_rename,
            "描述": "自动修改群昵称请指定记录名如bindWl"
        }
        return self._dict_to_str(conf_dict)
